// pages/details/details.js
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
      cid:"",
      wezhang:"",
      lyc:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var cid = options.id;
      var that=this;
      that.setData({
          cid: cid
      });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      var that = this
      var cid = that.data.cid
      wx.request({
          url: 'https://www.mayizhihuan.com/Home/Articlelittle/',
          data: {
              id: this.data.cid,
              PHPSESSID: wx.getStorageSync('sid')
          },
          method: 'GET',
          header: {
              'content-type': 'application/json'
          },
          success: function (res,data) {
              that.setData({
                  wezhang:res.data.datas
              })
              wx.setNavigationBarTitle({
                  title: res.data.datas.article_title
              })
              if (res.data.datas.article_content !== "") {
                  var cccc = res.data.datas.article_content;
                  WxParse.wxParse('cccc', 'html', cccc , that, 5);
              } else {
                  that.setData({
                      isdata: false
                  })
                 /**
        * WxParse.wxParse(bindName , type, data, target,imagePadding)
        * 1.bindName绑定的数据名(必填)
        * 2.type可以为html或者md(必填)
        * 3.data为传入的具体数据(必填)
        * 4.target为Page对象,一般为this(必填)
        * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
        */
              }
          }
      }),
      wx.request({
          url: 'https://www.mayizhihuan.com/Home/Articlelittle/maseage/',
          data: {
              id: cid,
              PHPSESSID: wx.getStorageSync('sid')
          },
          method: 'GET',
          header: {
              'content-type': 'application/json'
          },
          success: function (res) {
              that.setData({
                  lyc: res.data.datas
              })
          }
      })
  },
  liuyan: function (e) {
      wx.navigateTo({
          url: '../liuyan/liuyan?id=' + e.target.id
      })
  },
  bianse: function (res) {
      let arr = res.target.dataset.id.split(',')[0]
      let arr2 = res.target.dataset.id.split(',')[1]
      var lyc = this.data.lyc.slice(0);
      var tt = lyc.length;
      for (var i = 0; i < tt; i++) {
          if (arr == lyc[i].id) {
              console.log(lyc[i].bianse)
              if (lyc[i].bianse == "true") {
                  lyc[i].bianse = "false";
                  lyc[i].number--
              } else {
                  lyc[i].bianse = "true";
                  lyc[i].number++
              }
          }
      }
      this.setData({
          lyc: lyc
      })
      var that = this;
      wx.request({
          url: 'https://www.mayizhihuan.com/Home/Articlelittle/lzan',
          data: {
              id: arr,
              article_id: arr2,
              PHPSESSID: wx.getStorageSync('sid')
          },
          method: 'GET',
          header: {
              'content-type': 'application/json'
          },
          success: function (res) {

          }
      })
  },
  //   跳转另一个小程序
  gopage: function (e) {
      var id = e.currentTarget.dataset.id;
      wx.navigateToMiniProgram({
          appId: 'wxee94452a99e18b6d',
          path: '/pages/gooddetail/gooddetail?id=' + id,
          extraData: {
              foo: 'bar'
          },
          envVersion: 'develop',
          success(res) {
              // 打开成功
          }
      })
  },
  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function () {

  }
})